package com.rbac.mapper;

import com.rbac.pojo.Permission;
import com.rbac.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface LoginMapper {
    @Select("select * from permission where permission_id in " +
            "(select permission_id from role_permission where role_id in " +
            "(select role_id from role_user where user_id = #{userId}))" +
            "and menu_type != 'F' order by order_num")
    List<Permission> getPermissionByUserId(Integer userId);

    @Select("select * from permission where permission_id in " +
            "(select permission_id from role_permission where role_id in " +
            "(select role_id from role_user where user_id = #{userId}))" +
            "and menu_type == 'C' ")
    List<Permission> getRouteByUserId(Integer userId);

    @Select("select * from user where username = #{username}")
    User getUserByName(String username);

    @Select("select perms from permission where permission_id in (" +
            "(select permission_id from role_permission where role_id in " +
            "(select role_id from role_user where user_id = #{userId}))) " +
            "and perms is not null")
    List<String> getPermsListByUserId(Integer userId);
}
